package adapter;

import android.content.Context;
import android.graphics.Paint;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import bean.ZDInfo;
import yztc.com.shiyuanbaoyou.R;

/**
 * Created by My on 2016/9/24.
 */
public class ZDAdapter extends BaseAdapter {
    private Context context;
    private List<ZDInfo.RowsBean> list;

    public ZDAdapter(Context context, List<ZDInfo.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    ViewHolder holder=null;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            LayoutInflater inflater=LayoutInflater.from(context);
            convertView=inflater.inflate(R.layout.item_zd,null);
            holder=new ViewHolder();
            holder.iv= (SimpleDraweeView) convertView.findViewById(R.id.iv_zd_gv);
            holder.tv_title= (TextView) convertView.findViewById(R.id.tvtitle_zd_gv);
            holder.tv_price= (TextView) convertView.findViewById(R.id.tvprice_zd_gv);
            holder.tv_oldprice= (TextView) convertView.findViewById(R.id.tvoldprice_zd_gv);
            holder.tv_sale= (TextView) convertView.findViewById(R.id.tvsale_zd_gv);
            holder.tv_count= (TextView) convertView.findViewById(R.id.tvcount_zd_gv);
            convertView.setTag(holder);

        }else {
            holder= (ViewHolder) convertView.getTag();
        }
      /*  float   a  =   123.2334f;
        float  b   =  (float)(Math.round(a*100))/100;*/
        holder.iv.setImageURI(Uri.parse(list.get(position).getProductImg()));
        holder.tv_title.setText(list.get(position).getName());
        float a1= (float) list.get(position).getNewPrice();
        float b1=(float)(Math.round(a1*100))/100;
        holder.tv_price.setText("￥"+b1);
        float a2= (float) list.get(position).getOldPrice();
        float b2=(float)(Math.round(a2*100))/100;
        holder.tv_oldprice.setText(b2+"");
        holder.tv_oldprice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线
        float a3= (float) list.get(position).getDiscount();
        float b3=(float)(Math.round(a3*100))/100;
        holder.tv_sale.setText(b3+"折");
        holder.tv_count.setText("已售"+list.get(position).getSaleTotal()+"件");
        return convertView;
    }
    static class ViewHolder{
        SimpleDraweeView iv;
        TextView tv_title,tv_price,tv_oldprice,tv_sale,tv_count;
    }
}
